'Standadize variables
genr sun_std=(sun-@mean(sun))/@stdev(sun)
genr rain_rel_std=(rain_rel-@mean(rain_rel))/@stdev(rain_rel)
genr rain_abs_std=(rain_abs-@mean(rain_abs))/@stdev(rain_abs)
genr subjective_std=(subjective-@mean(subjective))/@stdev(subjective)


%var="nega" 	' Write "posi" for the positive affect, or "nega" for negative affect

' Standardize mood related variable
genr {%var}_std=({%var}-@mean({%var}))/@stdev({%var})

'Negative affect system

system {%var}_aff_sys
system {%var}_aff_sys_sobel_1
system {%var}_aff_sys_sobel_2

{%var}_aff_sys.append vote_choice=c(1)+c(2)*{%var}_std @ c {%var}_std
{%var}_aff_sys.gmm(bw=10)
vector temp_coefs={%var}_aff_sys.@coefs
vector temp_stderrs={%var}_aff_sys.@stderrs

equation {%var}_aff_sys_comp.ls {%var}_std=c(3)*sun_std+c(4)*rain_rel_std+c(5)*rain_abs_std+c(6)*subjective_std

'Sobel

!counter=1

for %weather_var sun_std rain_rel_std rain_abs_std subjective_std

{%var}_aff_sys_sobel_1.append {%var}_std=c(10)+c(11)*{%weather_var} @ c {%weather_var}
{%var}_aff_sys_sobel_1.gmm(bw=10)
vector temp_coefs_sobel_1={%var}_aff_sys_sobel_1.@coefs
vector temp_stderrs_sobel_1={%var}_aff_sys_sobel_1.@stderrs

{%var}_aff_sys_sobel_2.append vote_choice=c(7)+c(8)*{%var}_std+c(9)*{%weather_var} @ c {%var}_std {%weather_var}
{%var}_aff_sys_sobel_2.gmm(bw=10)
vector temp_coefs_sobel_2={%var}_aff_sys_sobel_2.@coefs
vector temp_stderrs_sobel_2={%var}_aff_sys_sobel_2.@stderrs

aaa_{%var}_affect(12+(!counter-1)*2,3) = temp_coefs_sobel_2(3)*temp_coefs_sobel_1(2)/sqr(temp_coefs_sobel_1(2)^2*temp_stderrs_sobel_2(3)^2+temp_coefs_sobel_2(3)^2*temp_stderrs_sobel_1(2)^2)
aaa_{%var}_affect(13+(!counter-1)*2,3) = @cnorm(-abs(temp_coefs_sobel_2(3)*temp_coefs_sobel_1(2)/sqr(temp_coefs_sobel_1(2)^2*temp_stderrs_sobel_2(3)^2+temp_coefs_sobel_2(3)^2*temp_stderrs_sobel_1(2)^2)))*2

'Update counter
!counter = !counter+1

next


'Store results

' First store coefficients
for !tab_ind=1 to 2
aaa_{%var}_affect(2+(!tab_ind-1)*2,3)=temp_coefs(!tab_ind) 
aaa_{%var}_affect(3+(!tab_ind-1)*2,3)=temp_stderrs(!tab_ind) 
' Assign significance stars
' 10% significance
if abs(temp_coefs(!tab_ind)/temp_stderrs(!tab_ind))<1.6449 then
aaa_{%var}_affect(2+(!tab_ind-1)*2,3+1)=" "
else
endif
' 10% significance
if abs(temp_coefs(!tab_ind)/temp_stderrs(!tab_ind))>1.6449 then
aaa_{%var}_affect(2+(!tab_ind-1)*2,3+1)="*"
else
endif
' 5% significance
if abs(temp_coefs(!tab_ind)/temp_stderrs(!tab_ind))>1.96 then
aaa_{%var}_affect(2+(!tab_ind-1)*2,3+1)="**"
else
endif
' 1% significance
if abs(temp_coefs(!tab_ind)/temp_stderrs(!tab_ind))>2.5758 then
aaa_{%var}_affect(2+(!tab_ind-1)*2,3+1)="***"
else
endif
next ' Ends loop on storing coefficients

'Housekeeping
d *temp* *_aff_sys* *_std

